package acwing._2LanQiao._4Enumerate;
/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._4Enumerate
 * @File : Q0466.java
 * @Author : WangRuoyu
 * @Date : 2023/3/15 17:18
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q0466 {
    static boolean isPalindrome(int x) {
        int year = x;
        int month = x % 10;
        x /= 10;
        month = month * 10 + x % 10;
        x /= 10;
        int day = x % 10;
        x /= 10;
        day = day * 10 + x;

        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            if ((day >= 1) && (day <= 31)) {
                return true;
            }
            return false;
        } else if (month == 4 || month == 6 || month == 9 || month == 11) {
            if ((day >= 1) && (day <= 30)) {
                return true;
            }
            return false;
        } else if (month == 2) {
            if (year % 4 == 0) {
                if ((day >= 1) && (day <= 29)) {
                    return true;
                }
                return false;
            } else {
                if ((day >= 1) && (day <= 28)) {
                    return true;
                }
                return false;
            }
        }
        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String ststr = br.readLine();
        int st8 = Integer.parseInt(ststr);
        int st4 = Integer.parseInt(ststr.substring(0, 4));
        String enstr = br.readLine();
        int end8 = Integer.parseInt(enstr);
        int end4 = Integer.parseInt(enstr.substring(0, 4));

        int res = 0;
        for (int i = st4; i <= end4; ++i) {
            if (isPalindrome(i)) {
                int x = i;
                int y = i;
                for (int j = 0; j < 4; j++) {
                    y = y * 10 + x % 10;
                    x /= 10;
                }
                if (y >= st8 && y <= end8) {
                    res++;
                }
            }
        }
        System.out.println(res);
    }
}